package com.jetinno.simple.utils

import android.content.res.Resources
import android.graphics.Color
import androidx.annotation.ArrayRes
import androidx.annotation.DimenRes
import androidx.annotation.StringRes
import com.jetinno.simple.SimpleApplication.Companion.sApplication

object ResourcesUtil {
    fun getResource(): Resources {
        return sApplication.getResources()
    }

    fun getString(@StringRes id: Int): String = getResource().getString(id)

    fun getString(@StringRes id: Int, vararg formatArgs: Any): String =
        getResource().getString(id, *formatArgs)

    fun getIntArray(@ArrayRes id: Int): IntArray = getResource().getIntArray(id)

    fun getDimension(@DimenRes id: Int): Float = getResource().getDimension(id)

    fun getColor(colorString: String?, defaultColor: Int): Int {
        return try {
            if (!colorString.isNullOrEmpty()) Color.parseColor(colorString) else defaultColor
        } catch (e: Exception) {
            e.printStackTrace()
            defaultColor
        }
    }
}
